<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('返回体详情')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-response-edit" th:object="${mockResponse}">
        <input name="responseId" th:field="*{responseId}" type="hidden">
        <input name="customHeader" th:field="*{customHeader}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">简述：</label>
            <div class="col-sm-8">
                <input name="description" th:field="*{description}" class="form-control" type="text"
                       placeholder="例：xxx场景返回的json" maxlength="50" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">响应HTTP码：</label>
            <div class="col-sm-8">
                <input name="statusCode" th:field="*{statusCode}" class="form-control" type="number" placeholder="例：200"
                       required max="999">
            </div>
        </div>
        <div class="form-group" th:if="${responseType == 'MANUAL'}">
            <label class="col-sm-3 control-label">请求方式：</label>
            <div class="col-sm-8">
                <select name="method" class="form-control m-b" th:with="type=${@dict.getType('http_method')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{method}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">自定义响应头：</label>
            <div class="col-sm-8">
                <button class="btn btn-default btn-circle" type="button" title="增加一个响应头"><i
                        class="fa fa-plus"></i>
                </button>
            </div>
        </div>
        <div id="headerArea">
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">返回体：</label>
            <div class="col-sm-8">
                     <pre id="content" class="form-control"
                          style="margin-bottom: 5px;height: 100%;">[[*{content}]]</pre>
                <span id="contentTip" style="color: red;font-weight: 700;"></span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = parent.prefix;
    $("#form-response-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-response-edit').serialize());
        }
    }

    CustomHeader.render($('[name="customHeader"]').val());
    // readonly
    $('input, textarea, select').attr("readonly", "readonly");
    $('.header-area button').removeClass('btn-warning');
    $('.header-area button').addClass('btn-default').attr('onclick', '');
    // response content tip text
    var responseContent = $('#content').html();
    // Check format
    // JOSN
    if (CU.isJson(responseContent)) {
        $('#contentTip').html('内容为[JSON]格式');
        $('#content').JSONView(responseContent);
        // XML
    } else if (CU.isXML($('<div/>').html(responseContent).text())) {
        $('#contentTip').html('内容为[XML]格式');
        $("#content").empty().simpleXML({xmlString: $('<div/>').html(responseContent).text()});
        // TEXT
    } else {
        $('#contentTip').html('内容为[普通文本]格式');
    }


</script>
</body>
</html>